﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Windows.Forms.DataVisualization.Charting;

namespace EasyTrader.Chart
{
    using PriceWaveList = List<EasyTrader.Wave.PriceWave>;
    using PricePointList = List<EasyTrader.Wave.PricePoint>;
    public partial class CPSvrNew7221OptionChartFrm : System.Windows.Forms.Form
    {

        private EasyTrader.Signal.TotalSignalManager m_GSignalManager = null;
        public EasyTrader.Signal.TotalSignalManager GSignalManager
        {
            get { return m_GSignalManager; }
            set { m_GSignalManager = value; }
        }

        public CPSvrNew7221OptionChartFrm()
        {
            InitializeComponent();
        }

        private void InitControl()
        {
            cbPersonCall.Checked = true;
            cbPersonPut.Checked = true;
            cbForeignCall.Checked = false;
            cbForeignPut.Checked = false;
            cbOrganCall.Checked = false;
            cbOrganPut.Checked = false;
            cbFore.Checked = true;
            cbPersonCallWave.Checked = false;
            cbPersonPutWave.Checked = false;
            cbPersonCallAve.Checked = false;
            cbPersonPutAve.Checked = false;

            CPSvrNew7221OptionChartCtrl.Series["외국인콜매수"].Enabled = false;
            CPSvrNew7221OptionChartCtrl.Series["외국인풋매수"].Enabled = false;
            CPSvrNew7221OptionChartCtrl.Series["기관콜매수"].Enabled = false;
            CPSvrNew7221OptionChartCtrl.Series["기관풋매수"].Enabled = false;


            CPSvrNew7221OptionChartCtrl.Series["개인콜매수"].ToolTip = "#VALX : #VAL";
            CPSvrNew7221OptionChartCtrl.Series["개인풋매수"].ToolTip = "#VALX : #VAL";
            CPSvrNew7221OptionChartCtrl.Series["외국인콜매수"].ToolTip = "#VALX : #VAL";
            CPSvrNew7221OptionChartCtrl.Series["외국인풋매수"].ToolTip = "#VALX : #VAL";
            CPSvrNew7221OptionChartCtrl.Series["기관콜매수"].ToolTip = "#VALX : #VAL";
            CPSvrNew7221OptionChartCtrl.Series["기관풋매수"].ToolTip = "#VALX : #VAL";

            CPSvrNew7221OptionChartCtrl.Series["개인콜예상가"].ToolTip = "#VALX : #VAL";
            CPSvrNew7221OptionChartCtrl.Series["개인풋예상가"].ToolTip = "#VALX : #VAL";

            CPSvrNew7221OptionChartCtrl.Series["개인콜중간가"].ToolTip = "#VALX : #VAL";
            CPSvrNew7221OptionChartCtrl.Series["개인풋중간가"].ToolTip = "#VALX : #VAL";
        }
    
        // Cybos Plus Data Set Member
        private ETDataSet m_CPDataSet = null;
        public EasyTrader.ETDataSet CPDataSet
        {
            get { return m_CPDataSet; }
            set { m_CPDataSet = value; }
        }
        private System.Windows.Forms.Timer timer = new System.Windows.Forms.Timer();
        private void InitTimer()
        {
            timer.Interval = GlobalVar.ChartRefreshInterval;
            timer.Tick += new EventHandler(OnTimerTick);
            timer.Start();
        }

        // 여기서 차트를 갱신해 준다.
        private void OnTimerTick(object sender, EventArgs e)
        {
            // 차트에 데이터를 대응시켜 준다.
            if (GlobalVar.OperationMode == GlobalVar.OperationModeNormal)
            {
                SetChartData();
                ShowCurValue();
                int dayIndex = GlobalVar.DayIndex();
                //SetCallAveValOnChart(dayIndex);
                //SetPutAveValOnChart(dayIndex);
            }
            else
            {
                SetChartData(GlobalVar.SimulIndex);
                ShowCurValue(GlobalVar.SimulIndex);
                //SetCallAveValOnChart(GlobalVar.SimulIndex);
                //SetPutAveValOnChart(GlobalVar.SimulIndex);
            }

            if (m_GSignalManager != null)
            {
                //PriceWaveList curWaveList = m_GSignalManager.ETSubjectSignalManager.CallWaveManager.ArragedWaveList;
                //SetCallWaveOnChart(curWaveList);

                //curWaveList = m_GSignalManager.ETSubjectSignalManager.PutWaveManager.ArragedWaveList;
                //SetPutWaveOnChart(curWaveList);
            }

            double totalSquare = m_GSignalManager.CallPutTotalSquareOcc;
            if (totalSquare != 0)
            {
                double pureCallSquare = Convert.ToDouble(m_GSignalManager.CallSquareOcc);
                double purePutSquare = Convert.ToDouble(m_GSignalManager.PutSquareOcc);
                double callS = totalSquare - purePutSquare;
                double putS = totalSquare - pureCallSquare;
                double callRatio = (callS / totalSquare);
                double putRatio = (putS / totalSquare);
                int buyVal = squareOccBar.Value = (int)(callRatio * 100);
                squareOccBar.LeftLabel = "콜 : " + buyVal.ToString() + "%";
                squareOccBar.RightLabel = "풋 : " + (putRatio * 100.0).ToString("F0") + "%";
            }

            double totalTime = Convert.ToDouble(m_GSignalManager.CallTimeOcc) + Convert.ToDouble(m_GSignalManager.PutTimeOcc);
            if (totalTime != 0)
            {
                double callTimeRatio = (Convert.ToDouble(m_GSignalManager.CallTimeOcc) / totalTime);
                int callVal = timeOccBar.Value = (int)(callTimeRatio * 100);
                timeOccBar.LeftLabel = "콜 : " + callVal.ToString() + "%";
                timeOccBar.RightLabel = "풋 : " + (100.0 - callVal).ToString() + "%";
            }

            //SetForecastingYOnChart();
        }

        private void SetCallAveValOnChart(int a_CurIndex)
        {
            if (a_CurIndex + 1 < GlobalVar.CallPutRefRange)
                return;
            CPSvrNew7221OptionChartCtrl.DataManipulator.FinancialFormula(FinancialFormula.ExponentialMovingAverage, GlobalVar.CallPutAveVal.ToString(), "개인콜매수", "개인콜중간가");
        }

        private void SetPutAveValOnChart(int a_CurIndex)
        {
            if (a_CurIndex + 1 < GlobalVar.CallPutRefRange)
                return;
            CPSvrNew7221OptionChartCtrl.DataManipulator.FinancialFormula(FinancialFormula.ExponentialMovingAverage, GlobalVar.CallPutAveVal.ToString(), "개인풋매수", "개인풋중간가");
        }


        private void SetCallWaveOnChart(PriceWaveList a_WaveList)
        {
            // 먼저 이전에 모든 점들을 없애 준다.
            CPSvrNew7221OptionChartCtrl.Series["개인콜파동"].Points.Clear();
            for (int i = 0; i < a_WaveList.Count; i++)
            {
                EasyTrader.Wave.PriceWave wave = a_WaveList[i];
                CPSvrNew7221OptionChartCtrl.Series["개인콜파동"].Points.AddXY(wave.StartX, wave.StartY / 100.0);
                // 파동은 마지막 점을 한번 더 넣어 준다.
                if (i == a_WaveList.Count - 1)
                {
                    CPSvrNew7221OptionChartCtrl.Series["개인콜파동"].Points.AddXY(wave.EndX, wave.EndY / 100.0);
                }
            }
        }

        private void SetPutWaveOnChart(PriceWaveList a_WaveList)
        {
            // 먼저 이전에 모든 점들을 없애 준다.
            CPSvrNew7221OptionChartCtrl.Series["개인풋파동"].Points.Clear();
            for (int i = 0; i < a_WaveList.Count; i++)
            {
                EasyTrader.Wave.PriceWave wave = a_WaveList[i];
                CPSvrNew7221OptionChartCtrl.Series["개인풋파동"].Points.AddXY(wave.StartX, wave.StartY / 100.0);
                // 파동은 마지막 점을 한번 더 넣어 준다.
                if (i == a_WaveList.Count - 1)
                {
                    CPSvrNew7221OptionChartCtrl.Series["개인풋파동"].Points.AddXY(wave.EndX, wave.EndY / 100.0);
                }
            }
        }


        private void SetForecastingYOnChart()
        {
            if (m_GSignalManager == null)
                return;


            EasyTrader.Signal.ForecastingInfo foreInfo = GSignalManager.PutPersonInfo;
            if (CPSvrNew7221OptionChartCtrl.Series["개인풋예상가"] != null && foreInfo != null)
            {
                CPSvrNew7221OptionChartCtrl.Series["개인풋예상가"].Points.Clear();
                CPSvrNew7221OptionChartCtrl.Series["개인풋예상가"].Points.AddXY(foreInfo.StartX, foreInfo.StartY / 100);
                CPSvrNew7221OptionChartCtrl.Series["개인풋예상가"].Points.AddXY(foreInfo.EndX, foreInfo.EndY / 100);
                txtPersonPutAngle.Text = "개인풋각도 : " + foreInfo.Angle.ToString("F2");
            }

            foreInfo = GSignalManager.CallPersonInfo;
            if (CPSvrNew7221OptionChartCtrl.Series["개인콜예상가"] != null && foreInfo != null)
            {
                CPSvrNew7221OptionChartCtrl.Series["개인콜예상가"].Points.Clear();
                CPSvrNew7221OptionChartCtrl.Series["개인콜예상가"].Points.AddXY(foreInfo.StartX, foreInfo.StartY / 100);
                CPSvrNew7221OptionChartCtrl.Series["개인콜예상가"].Points.AddXY(foreInfo.EndX, foreInfo.EndY / 100);
                txtPersonCallAngle.Text = "개인콜각도 : " + foreInfo.Angle.ToString("F2");
            }
        }

        private void ShowCurValue()
        {
            // 데이터 셋 객체가 없으면 아무일도 하지 않는다.
            if (m_CPDataSet == null || GlobalVar.CPSvrNew7221DataDownloaded == false)
                return;

            CPSvrNew7221Table dataTable = m_CPDataSet.GetCPSvrNew7221Table();
            int rowCount = dataTable.GetRowCount();
            if (rowCount == 0)
                return;

            DataRow row = dataTable.Rows[rowCount - 1];
            if (row["코스피개인순매수"] == DBNull.Value)
                return;

            double personVal = Convert.ToDouble(row["개인옵션콜순매수"]) / 100;
            double personVal1 = Convert.ToDouble(row["개인옵션풋순매수"]) / 100;
            double foreignVal = Convert.ToDouble(row["외국인옵션콜순매수"]) / 100;
            double foreignVal1 = Convert.ToDouble(row["외국인옵션풋순매수"]) / 100;
            double organVal = Convert.ToDouble(row["기관계옵션콜순매수"]) / 100;
            double organVal1 = Convert.ToDouble(row["기관계옵션풋순매수"]) / 100;
            string curTime = row["시각"].ToString();
            if (curTime != "0")
            {
                string minText = curTime.Substring(curTime.Length - 2, 2);
                string hourText = curTime.Substring(0, curTime.Length - 2);

                txtCurTime.Text = "현재시간 " + hourText + " : " + minText;
                txtCurPrice.Text = "개인콜순매수 : " + personVal.ToString("F2") + " , 개인풋순매수 : " + personVal1.ToString("F2");
                txtCurPrice2.Text = "외국인콜순매수 : " + foreignVal.ToString("F2") + ", 외국인풋순매수 : " + foreignVal1.ToString("F2");
                txtCurPrice3.Text = "기관계콜순매수 : " + organVal.ToString("F2") + ",  기관계풋순매수 : " + organVal1.ToString("F2");
            }
        }

        private void ShowCurValue(int a_CurIndex)
        {
            // 데이터 셋 객체가 없으면 아무일도 하지 않는다.
            if (m_CPDataSet == null)
                return;

            CPSvrNew7221Table dataTable = m_CPDataSet.GetCPSvrNew7221Table();
            int rowCount = dataTable.GetRowCount();
            if (rowCount == 0)
                return;
            if (rowCount - 1 < a_CurIndex)
                return;

            DataRow row = dataTable.Rows[a_CurIndex];
            if (row["코스피개인순매수"] == DBNull.Value)
                return;

            double personVal = Convert.ToDouble(row["개인옵션콜순매수"]) / 100;
            double personVal1 = Convert.ToDouble(row["개인옵션풋순매수"]) / 100;
            double foreignVal = Convert.ToDouble(row["외국인옵션콜순매수"]) / 100;
            double foreignVal1 = Convert.ToDouble(row["외국인옵션풋순매수"]) / 100;
            double organVal = Convert.ToDouble(row["기관계옵션콜순매수"]) / 100;
            double organVal1 = Convert.ToDouble(row["기관계옵션풋순매수"]) / 100;
            string curTime = row["시각"].ToString();
            if (curTime != "0")
            {
                string minText = curTime.Substring(curTime.Length - 2, 2);
                string hourText = curTime.Substring(0, curTime.Length - 2);

                txtCurTime.Text = "현재시간 " + hourText + " : " + minText;
                txtCurPrice.Text = "개인콜순매수 : " + personVal.ToString("F2") + " , 개인풋순매수 : " + personVal1.ToString("F2");
                txtCurPrice2.Text = "외국인콜순매수 : " + foreignVal.ToString("F2") + ", 외국인풋순매수 : " + foreignVal1.ToString("F2");
                txtCurPrice3.Text = "기관계콜순매수 : " + organVal.ToString("F2") + ",  기관계풋순매수 : " + organVal1.ToString("F2");
            }
        }

        private void SetChartData()
        {
            // 데이터 셋 객체가 없으면 아무일도 하지 않는다.
            if (m_CPDataSet == null)
                return;

            CPSvrNew7221OptionChartCtrl.Series["개인콜매수"].Points.Clear();
            CPSvrNew7221OptionChartCtrl.Series["개인풋매수"].Points.Clear();
            CPSvrNew7221OptionChartCtrl.Series["외국인콜매수"].Points.Clear();
            CPSvrNew7221OptionChartCtrl.Series["외국인풋매수"].Points.Clear();
            CPSvrNew7221OptionChartCtrl.Series["기관콜매수"].Points.Clear();
            CPSvrNew7221OptionChartCtrl.Series["기관풋매수"].Points.Clear();
            CPSvrNew7221Table dataTable = m_CPDataSet.GetCPSvrNew7221Table();
            double maxValue = -10000.0;
            double minValue = 10000.0;
            int rowCount = dataTable.GetRowCount();
            if (rowCount == 0)
                return;

            int minIndex = 0;
            int maxIndex = 0;
            double personCall = 0;
            double personPut = 0;
            double foreignCall = 0;
            double foreignPut = 0;
            double organCall = 0;
            double organPut = 0;
            for (int i = 0; i < rowCount; i++)
            {
                DataRow row = dataTable.Rows[i];
                try
                {
                    // 값이 없을 경우는 넘어 간다.
                    if (row["개인옵션콜순매수"] == DBNull.Value)
                        continue;

                    personCall = Convert.ToDouble(row["개인옵션콜순매수"]) / 100;
                    personPut = Convert.ToDouble(row["개인옵션풋순매수"]) / 100;
                    foreignCall = Convert.ToDouble(row["외국인옵션콜순매수"]) / 100;
                    foreignPut = Convert.ToDouble(row["외국인옵션풋순매수"]) / 100;
                    organCall = Convert.ToDouble(row["기관계옵션콜순매수"]) / 100;
                    organPut = Convert.ToDouble(row["기관계옵션풋순매수"]) / 100;
                    CPSvrNew7221OptionChartCtrl.Series["개인콜매수"].Points.AddXY(i, personCall);
                    CPSvrNew7221OptionChartCtrl.Series["개인풋매수"].Points.AddXY(i, personPut);
                    CPSvrNew7221OptionChartCtrl.Series["외국인콜매수"].Points.AddXY(i, foreignCall);
                    CPSvrNew7221OptionChartCtrl.Series["외국인풋매수"].Points.AddXY(i, foreignPut);
                    CPSvrNew7221OptionChartCtrl.Series["기관콜매수"].Points.AddXY(i, organCall);
                    CPSvrNew7221OptionChartCtrl.Series["기관풋매수"].Points.AddXY(i, organPut);
                    CPSvrNew7221OptionChartCtrl.Series["개인콜매수"].Points[i].XValue = i;
                    //CPSvrNew7221OptionChartCtrl.Series["개인콜매수"].Points[i].AxisLabel = row["시각"].ToString();
                    int hour = Convert.ToInt32(row["시각"]);
                    if (hour != 0)
                        CPSvrNew7221OptionChartCtrl.Series["개인콜매수"].Points[i].AxisLabel = row["시각"].ToString();
                    else
                        CPSvrNew7221OptionChartCtrl.Series["개인콜매수"].Points[i].AxisLabel = GlobalVar.DayIndexToTime(i).ToString();

                    
                    if (personCall != 0 && personCall > maxValue)
                    {
                        maxValue = personCall;
                        maxIndex = i;
                    }

                    if (foreignCall != 0 && foreignCall > maxValue)
                    {
                        maxValue = foreignCall;
                        maxIndex = i;
                    }

                    if (organCall != 0 && organCall > maxValue)
                    {
                        maxValue = organCall;
                        maxIndex = i;
                    }

                    if (personPut != 0 && personPut > maxValue)
                    {
                        maxValue = personPut;
                        maxIndex = i;
                    }

                    if (foreignPut != 0 && foreignPut > maxValue)
                    {
                        maxValue = foreignPut;
                        maxIndex = i;
                    }

                    if (organPut != 0 && organPut > maxValue)
                    {
                        maxValue = organPut;
                        maxIndex = i;
                    }

                    if (personCall != 0 && personCall < minValue)
                    {
                        minValue = personCall;
                        minIndex = i;
                    }

                    if (foreignCall != 0 && foreignCall < minValue)
                    {
                        minValue = foreignCall;
                        minIndex = i;
                    }

                    if (organCall != 0 && organCall < minValue)
                    {
                        minValue = organCall;
                        minIndex = i;
                    }

                    if (personPut != 0 && personPut < minValue)
                    {
                        minValue = personPut;
                        minIndex = i;
                    }

                    if (foreignPut != 0 && foreignPut < minValue)
                    {
                        minValue = foreignPut;
                        minIndex = i;
                    }

                    if (organPut != 0 && organPut < minValue)
                    {
                        minValue = organPut;
                        minIndex = i;
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.ToString());
                }
            }

            int valueHeight = (int)maxValue / 25;
            maxValue = (valueHeight + 1) * 25;

            if (maxValue >= minValue)
            {
                CPSvrNew7221OptionChartCtrl.ChartAreas["Price"].AxisY.Minimum = minValue;
                CPSvrNew7221OptionChartCtrl.ChartAreas["Price"].AxisY.Maximum = maxValue;
            }
        }

        private void SetChartData(int a_CurIndex)
        {
            // 데이터 셋 객체가 없으면 아무일도 하지 않는다.
            if (m_CPDataSet == null)
                return;

            CPSvrNew7221OptionChartCtrl.Series["개인콜매수"].Points.Clear();
            CPSvrNew7221OptionChartCtrl.Series["개인풋매수"].Points.Clear();
            CPSvrNew7221OptionChartCtrl.Series["외국인콜매수"].Points.Clear();
            CPSvrNew7221OptionChartCtrl.Series["외국인풋매수"].Points.Clear();
            CPSvrNew7221OptionChartCtrl.Series["기관콜매수"].Points.Clear();
            CPSvrNew7221OptionChartCtrl.Series["기관풋매수"].Points.Clear();
            CPSvrNew7221Table dataTable = m_CPDataSet.GetCPSvrNew7221Table();
            double maxValue = -10000.0;
            double minValue = 10000.0;
            int rowCount = dataTable.GetRowCount();
            if (rowCount == 0)
                return;
            if (rowCount - 1 < a_CurIndex)
                return;

            int minIndex = 0;
            int maxIndex = 0;
            double personCall = 0;
            double personPut = 0;
            double foreignCall = 0;
            double foreignPut = 0;
            double organCall = 0;
            double organPut = 0;
            for (int i = 0; i <= a_CurIndex; i++)
            {
                DataRow row = dataTable.Rows[i];
                try
                {
                    // 값이 없을 경우는 넘어 간다.
                    if (row["개인옵션콜순매수"] == DBNull.Value)
                        continue;

                    personCall = Convert.ToDouble(row["개인옵션콜순매수"]) / 100;
                    personPut = Convert.ToDouble(row["개인옵션풋순매수"]) / 100;
                    foreignCall = Convert.ToDouble(row["외국인옵션콜순매수"]) / 100;
                    foreignPut = Convert.ToDouble(row["외국인옵션풋순매수"]) / 100;
                    organCall = Convert.ToDouble(row["기관계옵션콜순매수"]) / 100;
                    organPut = Convert.ToDouble(row["기관계옵션풋순매수"]) / 100;
                    CPSvrNew7221OptionChartCtrl.Series["개인콜매수"].Points.AddXY(i, personCall);
                    CPSvrNew7221OptionChartCtrl.Series["개인풋매수"].Points.AddXY(i, personPut);
                    CPSvrNew7221OptionChartCtrl.Series["외국인콜매수"].Points.AddXY(i, foreignCall);
                    CPSvrNew7221OptionChartCtrl.Series["외국인풋매수"].Points.AddXY(i, foreignPut);
                    CPSvrNew7221OptionChartCtrl.Series["기관콜매수"].Points.AddXY(i, organCall);
                    CPSvrNew7221OptionChartCtrl.Series["기관풋매수"].Points.AddXY(i, organPut);
                    CPSvrNew7221OptionChartCtrl.Series["개인콜매수"].Points[i].XValue = i;
                    //CPSvrNew7221OptionChartCtrl.Series["개인콜매수"].Points[i].AxisLabel = row["시각"].ToString();
                    int hour = Convert.ToInt32(row["시각"]);
                    if (hour != 0)
                        CPSvrNew7221OptionChartCtrl.Series["개인콜매수"].Points[i].AxisLabel = row["시각"].ToString();
                    else
                        CPSvrNew7221OptionChartCtrl.Series["개인콜매수"].Points[i].AxisLabel = GlobalVar.DayIndexToTime(i).ToString();


                    if (personCall != 0 && personCall > maxValue)
                    {
                        maxValue = personCall;
                        maxIndex = i;
                    }

                    if (foreignCall != 0 && foreignCall > maxValue)
                    {
                        maxValue = foreignCall;
                        maxIndex = i;
                    }

                    if (organCall != 0 && organCall > maxValue)
                    {
                        maxValue = organCall;
                        maxIndex = i;
                    }

                    if (personPut != 0 && personPut > maxValue)
                    {
                        maxValue = personPut;
                        maxIndex = i;
                    }

                    if (foreignPut != 0 && foreignPut > maxValue)
                    {
                        maxValue = foreignPut;
                        maxIndex = i;
                    }

                    if (organPut != 0 && organPut > maxValue)
                    {
                        maxValue = organPut;
                        maxIndex = i;
                    }

                    if (personCall != 0 && personCall < minValue)
                    {
                        minValue = personCall;
                        minIndex = i;
                    }

                    if (foreignCall != 0 && foreignCall < minValue)
                    {
                        minValue = foreignCall;
                        minIndex = i;
                    }

                    if (organCall != 0 && organCall < minValue)
                    {
                        minValue = organCall;
                        minIndex = i;
                    }

                    if (personPut != 0 && personPut < minValue)
                    {
                        minValue = personPut;
                        minIndex = i;
                    }

                    if (foreignPut != 0 && foreignPut < minValue)
                    {
                        minValue = foreignPut;
                        minIndex = i;
                    }

                    if (organPut != 0 && organPut < minValue)
                    {
                        minValue = organPut;
                        minIndex = i;
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.ToString());
                }
            }

            int valueHeight = (int)maxValue / 25;
            maxValue = (valueHeight + 1) * 25;

            if (maxValue >= minValue)
            {
                CPSvrNew7221OptionChartCtrl.ChartAreas["Price"].AxisY.Minimum = minValue;
                CPSvrNew7221OptionChartCtrl.ChartAreas["Price"].AxisY.Maximum = maxValue;
            }
        }

        public CPSvrNew7221OptionChartFrm(ETDataSet a_DataSet)
        {
            InitializeComponent();
            m_CPDataSet = a_DataSet;
            InitControl();
        }

        private void InitChart()
        {
            CPSvrNew7221OptionChartCtrl.BackColor = System.Drawing.Color.FromArgb(((System.Byte)(211)), ((System.Byte)(223)), ((System.Byte)(240)));
            CPSvrNew7221OptionChartCtrl.BackSecondaryColor = System.Drawing.Color.White;
            CPSvrNew7221OptionChartCtrl.BackGradientStyle = System.Windows.Forms.DataVisualization.Charting.GradientStyle.TopBottom;
            CPSvrNew7221OptionChartCtrl.BorderlineColor = System.Drawing.Color.FromArgb(((System.Byte)(26)), ((System.Byte)(59)), ((System.Byte)(105)));
            CPSvrNew7221OptionChartCtrl.BorderlineDashStyle = System.Windows.Forms.DataVisualization.Charting.ChartDashStyle.Solid;
            CPSvrNew7221OptionChartCtrl.BorderlineWidth = 2;
            CPSvrNew7221OptionChartCtrl.BorderSkin.SkinStyle = System.Windows.Forms.DataVisualization.Charting.BorderSkinStyle.Emboss;

            CPSvrNew7221OptionChartCtrl.ChartAreas["Price"].AxisX.MajorGrid.Interval = 10;
            CPSvrNew7221OptionChartCtrl.ChartAreas["Price"].AxisX.Interval = 10;
            CPSvrNew7221OptionChartCtrl.ChartAreas["Price"].AxisY.MajorGrid.Interval = 100;
            CPSvrNew7221OptionChartCtrl.ChartAreas["Price"].AxisY.MinorGrid.Interval = 50;
            CPSvrNew7221OptionChartCtrl.ChartAreas["Price"].AxisY.Interval = 50;

            CPSvrNew7221OptionChartCtrl.ChartAreas["Price"].Area3DStyle.IsClustered = true;
            CPSvrNew7221OptionChartCtrl.ChartAreas["Price"].Area3DStyle.Perspective = 10;
            CPSvrNew7221OptionChartCtrl.ChartAreas["Price"].Area3DStyle.IsRightAngleAxes = false;
            CPSvrNew7221OptionChartCtrl.ChartAreas["Price"].Area3DStyle.WallWidth = 0;
            CPSvrNew7221OptionChartCtrl.ChartAreas["Price"].Area3DStyle.Inclination = 15;
            CPSvrNew7221OptionChartCtrl.ChartAreas["Price"].Area3DStyle.Rotation = 10;
            CPSvrNew7221OptionChartCtrl.ChartAreas["Price"].AxisX.IsLabelAutoFit = true;
            CPSvrNew7221OptionChartCtrl.ChartAreas["Price"].AxisX.LabelStyle.Font = new System.Drawing.Font("Trebuchet MS", 8.25F, System.Drawing.FontStyle.Bold);
            CPSvrNew7221OptionChartCtrl.ChartAreas["Price"].AxisX.LabelStyle.IsEndLabelVisible = false;
            CPSvrNew7221OptionChartCtrl.ChartAreas["Price"].AxisX.LineColor = System.Drawing.Color.FromArgb(((System.Byte)(64)), ((System.Byte)(64)), ((System.Byte)(64)), ((System.Byte)(64)));
            CPSvrNew7221OptionChartCtrl.ChartAreas["Price"].AxisX.MajorGrid.LineColor = System.Drawing.Color.FromArgb(((System.Byte)(64)), ((System.Byte)(64)), ((System.Byte)(64)), ((System.Byte)(64)));
            CPSvrNew7221OptionChartCtrl.ChartAreas["Price"].AxisY.IsLabelAutoFit = true;
            CPSvrNew7221OptionChartCtrl.ChartAreas["Price"].AxisY.LabelStyle.Font = new System.Drawing.Font("Trebuchet MS", 8.25F, System.Drawing.FontStyle.Bold);
            CPSvrNew7221OptionChartCtrl.ChartAreas["Price"].AxisY.LineColor = System.Drawing.Color.FromArgb(((System.Byte)(64)), ((System.Byte)(64)), ((System.Byte)(64)), ((System.Byte)(64)));
            CPSvrNew7221OptionChartCtrl.ChartAreas["Price"].AxisY.MajorGrid.LineColor = System.Drawing.Color.FromArgb(((System.Byte)(64)), ((System.Byte)(64)), ((System.Byte)(64)), ((System.Byte)(64)));
            CPSvrNew7221OptionChartCtrl.ChartAreas["Price"].AxisY.IsStartedFromZero = false;
            CPSvrNew7221OptionChartCtrl.ChartAreas["Price"].AxisY.MinorGrid.LineColor = System.Drawing.Color.FromArgb(((System.Byte)(64)), ((System.Byte)(64)), ((System.Byte)(64)), ((System.Byte)(64)));
            CPSvrNew7221OptionChartCtrl.ChartAreas["Price"].AxisY.MinorGrid.LineDashStyle = System.Windows.Forms.DataVisualization.Charting.ChartDashStyle.DashDot;

            //CPSvrNew7221OptionChartCtrl.ChartAreas["Price"].AxisY.LabelAutoFitMaxFontSize;
            CPSvrNew7221OptionChartCtrl.ChartAreas["Price"].BackColor = System.Drawing.Color.FromArgb(((System.Byte)(64)), ((System.Byte)(165)), ((System.Byte)(191)), ((System.Byte)(228)));
            CPSvrNew7221OptionChartCtrl.ChartAreas["Price"].BackSecondaryColor = System.Drawing.Color.White;
            CPSvrNew7221OptionChartCtrl.ChartAreas["Price"].BackGradientStyle = System.Windows.Forms.DataVisualization.Charting.GradientStyle.TopBottom;
            CPSvrNew7221OptionChartCtrl.ChartAreas["Price"].BorderColor = System.Drawing.Color.FromArgb(((System.Byte)(64)), ((System.Byte)(64)), ((System.Byte)(64)), ((System.Byte)(64)));
            CPSvrNew7221OptionChartCtrl.ChartAreas["Price"].BorderDashStyle = System.Windows.Forms.DataVisualization.Charting.ChartDashStyle.Solid;
            CPSvrNew7221OptionChartCtrl.ChartAreas["Price"].Position.Auto = true;
            //CPSvrNew7221OptionChartCtrl.ChartAreas["Price"].Position.Height = 80F;
            //CPSvrNew7221OptionChartCtrl.ChartAreas["Price"].Position.Width = 80F;
            //CPSvrNew7221OptionChartCtrl.ChartAreas["Price"].Position.X = 5F;
            //CPSvrNew7221OptionChartCtrl.ChartAreas["Price"].Position.Y = 10F;
            CPSvrNew7221OptionChartCtrl.ChartAreas["Price"].ShadowColor = System.Drawing.Color.Transparent;
            
            
            //CPSvrNew7221OptionChartCtrl.Series["지수"].ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Line;
             

            //CPSvrNew7221OptionChartCtrl.Series[0]["PriceUpColor"] = "blue";
            //CPSvrNew7221OptionChartCtrl.Series[0]["PriceDownColor"] = "Red";
            //CPSvrNew7221OptionChartCtrl.ChartAreas["Price"].AxisX.LabelStyle.IsEndLabelVisible = true;
            //CPSvrNew7221OptionChartCtrl.ChartAreas["Price"].AxisX.IsMarginVisible = true;
            //CPSvrNew7221OptionChartCtrl.ChartAreas["Price"].AxisY.LabelStyle.IsEndLabelVisible = true;
            //CPSvrNew7221OptionChartCtrl.ChartAreas["Price"].AxisY.IsMarginVisible = true;
            //CPSvrNew7221OptionChartCtrl.Series[0].Color = Color.Red;
            //DataPointCustomProperties aa = CPSvrNew7221OptionChartCtrl.Series[0]["PriceUpColor"];
            System.Windows.Forms.DataVisualization.Charting.StripLine stripLine = new System.Windows.Forms.DataVisualization.Charting.StripLine();
            stripLine.Interval = 0;
            stripLine.IntervalOffset = 0;
            stripLine.BackColor = Color.Black;
            stripLine.StripWidth = 0.0;
            stripLine.Text = "기준선 : 0";
            stripLine.TextAlignment = StringAlignment.Near;
            CPSvrNew7221OptionChartCtrl.ChartAreas[0].AxisY.StripLines.Add(stripLine);
        }

        private void CPSvrNew7221OptionChart_Load(object sender, EventArgs e)
        {
            InitChart();
            InitTimer();
        }

        private void CPSvrNew7221OptionChart_FormClosing(object sender, FormClosingEventArgs e)
        {
            timer.Stop();
        }

        private void cbPersonCall_CheckedChanged(object sender, EventArgs e)
        {
            if (cbPersonCall.Checked)
            {
                CPSvrNew7221OptionChartCtrl.Series["개인콜매수"].Enabled = true;
            }
            else
            {
                CPSvrNew7221OptionChartCtrl.Series["개인콜매수"].Enabled = false;
            }
        }

        private void cbPersonPut_CheckedChanged(object sender, EventArgs e)
        {
            if (cbPersonPut.Checked)
            {
                CPSvrNew7221OptionChartCtrl.Series["개인풋매수"].Enabled = true;
            }
            else
            {
                CPSvrNew7221OptionChartCtrl.Series["개인풋매수"].Enabled = false;
            }
        }

        private void cbForeignCall_CheckedChanged(object sender, EventArgs e)
        {
            if (cbForeignCall.Checked)
            {
                CPSvrNew7221OptionChartCtrl.Series["외국인콜매수"].Enabled = true;
            }
            else
            {
                CPSvrNew7221OptionChartCtrl.Series["외국인콜매수"].Enabled = false;
            }
        }

        private void cbForeignPut_CheckedChanged(object sender, EventArgs e)
        {
            if (cbForeignPut.Checked)
            {
                CPSvrNew7221OptionChartCtrl.Series["외국인풋매수"].Enabled = true;
            }
            else
            {
                CPSvrNew7221OptionChartCtrl.Series["외국인풋매수"].Enabled = false;
            }
        }

        private void cbOrganCall_CheckedChanged(object sender, EventArgs e)
        {
            if (cbOrganCall.Checked)
            {
                CPSvrNew7221OptionChartCtrl.Series["기관콜매수"].Enabled = true;
            }
            else
            {
                CPSvrNew7221OptionChartCtrl.Series["기관콜매수"].Enabled = false;
            }
        }

        private void cbOrganPut_CheckedChanged(object sender, EventArgs e)
        {
            if (cbOrganPut.Checked)
            {
                CPSvrNew7221OptionChartCtrl.Series["기관풋매수"].Enabled = true;
            }
            else
            {
                CPSvrNew7221OptionChartCtrl.Series["기관풋매수"].Enabled = false;
            }
        }

        private void cbFore_CheckedChanged(object sender, EventArgs e)
        {
            if (cbFore.Checked == true)
            {
                CPSvrNew7221OptionChartCtrl.Series["개인풋예상가"].Enabled = true;
                CPSvrNew7221OptionChartCtrl.Series["개인콜예상가"].Enabled = true;
            }
            else
            {
                CPSvrNew7221OptionChartCtrl.Series["개인콜예상가"].Enabled = false;
                CPSvrNew7221OptionChartCtrl.Series["개인콜예상가"].Enabled = false;
            }
        }

        private void cbPersonCallWave_CheckedChanged(object sender, EventArgs e)
        {
            if (cbPersonCallWave.Checked)
            {
                CPSvrNew7221OptionChartCtrl.Series["개인콜파동"].Enabled = true;
            }
            else
            {
                CPSvrNew7221OptionChartCtrl.Series["개인콜파동"].Enabled = false;
            }
        }

        private void cbPersonPutWave_CheckedChanged(object sender, EventArgs e)
        {
            if (cbPersonPutWave.Checked)
            {
                CPSvrNew7221OptionChartCtrl.Series["개인풋파동"].Enabled = true;
            }
            else
            {
                CPSvrNew7221OptionChartCtrl.Series["개인풋파동"].Enabled = false;
            }
        }

        private void cbPersonCallAve_CheckedChanged(object sender, EventArgs e)
        {
            if (cbPersonCallAve.Checked)
            {
                CPSvrNew7221OptionChartCtrl.Series["개인콜중간가"].Enabled = true;
            }
            else
            {
                CPSvrNew7221OptionChartCtrl.Series["개인콜중간가"].Enabled = false;
            }
        }

        private void cbPersonPutAve_CheckedChanged(object sender, EventArgs e)
        {
            if (cbPersonPutAve.Checked)
            {
                CPSvrNew7221OptionChartCtrl.Series["개인풋중간가"].Enabled = true;
            }
            else
            {
                CPSvrNew7221OptionChartCtrl.Series["개인풋중간가"].Enabled = false;
            }
        }
    }
}
